package leetcode.tanxin;

import java.util.Arrays;

/**
 * @title: Candy135
 * @Author jianglei
 * @Date: 2021/12/5 15:12
 * @Version 1.0
 */
public class Candy135 {
    public static void main(String[] args) {
        int [] res = new int[]{1,0,2};
        System.out.println(candy(res));
    }

    public static int candy(int[] ratings) {
        int [] resCandy = new int[ratings.length];
        Arrays.fill(resCandy, 1);

        for(int i =1;i<ratings.length;i++){//如果评分高，就加一
            if(ratings[i]>ratings[i-1])
                resCandy[i] = resCandy[i-1]+1;
        }
        for(int i =ratings.length-1;i>0;i--){//如果左边的评分高，并且糖果少。就加一
            if(ratings[i-1]>ratings[i] && resCandy[i-1]<=resCandy[i])
                resCandy[i-1] = resCandy[i]+1;
        }

        int res = 0;
        for (int i : resCandy) {
            res += i;
            System.out.print(i+ " ");
        }
        System.out.println();
        return res;
    }
}